Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 10897 - Travelling Distance / 10897.cpp
bloba8947137c7c02c0544ed528d1320d2868da0e01d
1 /*
2 Accepted
3 */
4 using namespace std;
5 #include <algorithm>
6 #include <iostream>
7 #include <iterator>
8 #include <sstream>
9 #include <fstream>
10 #include <cassert>
11 #include <climits>
12 #include <cstdlib>
13 #include <cstring>
14 #include <string>
15 #include <cstdio>
16 #include <cmath>
17 #include <queue>
18 #include <deque>
19 #include <stack>
20 #include <map>
21 #include <set>
23 #define D(x) cout << #x " is " << x << endl
25 const long double rho = 6371.01;//km
26 const long double pi = 2*acos(0.0);
28 struct Vector{
29 long double x, y, z;
30 long double dot(const Vector &t) const {
31 return x*t.x + y*t.y + z*t.z;
33 long double mag() const{
34 return sqrt(x*x + y*y + z*z);
38 ostream& operator << (ostream &out, Vector &v){
39 out << "<" << v.x << ", " << v.y << ", " << v.z << ">";
42 struct point{
43 long double phi, theta;
44 Vector toVector() const{
45 Vector v;
46 v.x = sin(phi)*cos(theta);
47 v.y = sin(phi)*sin(theta);
48 v.z = cos(phi);
49 return v;
53 istream& operator >> (istream &in, point &p){
54 long double a, b, c, d, e, f;
55 char X, Y;
56 in >> a >> b >> c >> X >> d >> e >> f >> Y;
58 long double latitude, longitude;
59 latitude = (a + b/60.0 + c/3600.0);
60 longitude = (d + e/60.0 + f/3600.0);
62 p.phi = 90 + latitude * (X == 'N' ? -1.0 : 1.0);
63 p.theta = longitude * (Y == 'E' ? -1.0 : 1.0);
66 D(p.phi), D(p.theta);
67 cout << endl;
70 p.phi *= pi/180.0, p.theta *= pi/180.0; //"radianize"
72 return in;
75 long double dist(point &a, point &b){
76 Vector va = a.toVector(), vb = b.toVector();
79 cout << "Point A as a vector = " << va << endl;
80 cout << "Point B as a vector = " << vb << endl;
81 cout << endl;
83 cout << "|A| = " << va.mag() << endl;
84 cout << "|B| = " << vb.mag() << endl;
87 long double angle = acos(va.dot(vb));
88 return rho * angle;
91 int main(){
92 int n;
93 for (scanf("%d", &n); n--; ){
94 point a, b;
95 cin >> a >> b;
96 printf("%.2llf\n", dist(a, b));
99 return 0;